package com.hy.controller;

import com.hy.Result.ResponseResult;
import com.hy.pojo.vaccine.VaccineCategory;
import com.hy.service.VaccineCategoryService;
import com.hy.pojeVo.QueryParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 疫苗分类控制器
 */
@RestController
@RequestMapping("/api/vaccineCategory")
public class VaccineCategoryController {

    @Autowired
    private VaccineCategoryService vaccineCategoryService;
    /**
     * 根据分类ID查询疫苗列表
     * @param categoryId 分类ID，不传则查询所有疫苗
     */
    @GetMapping("/vaccines")
    public ResponseResult getVaccinesByCategoryId(@RequestParam(required = false) Long categoryId) {
        return vaccineCategoryService.findVaccinesByCategoryId(categoryId);
    }


    /**
     * 获取疫苗分类列表（简单信息）
     */
    @GetMapping("/search")
    public List<VaccineCategory> searchByName() {
        return vaccineCategoryService.findByName();
    }

    /**
     * 获取疫苗分类列表（完整信息）
     */
    @GetMapping("/findAll")
    public List<VaccineCategory> searchName() {
        return vaccineCategoryService.findName();
    }


    /**
     * 分页查询疫苗分类
     */
    @PostMapping("/page")
    public ResponseResult searchByNamePage(@RequestBody QueryParam queryParam) {
        return vaccineCategoryService.searchByKeyword(queryParam);
    }

    @PostMapping("/saveVaccineCategory")
    public ResponseResult saveVaccineCategory(@RequestBody VaccineCategory vaccineCategory) {
        boolean save = vaccineCategoryService.save(vaccineCategory);
        if (save) {
            return new ResponseResult(200, "添加成功", null);
        }
        return new ResponseResult(400, "添加失败", null);
    }
    @PostMapping("/updateVaccineCategory")
    public ResponseResult updateVaccineCategory(@RequestBody VaccineCategory vaccineCategory) {
        boolean update = vaccineCategoryService.updateById(vaccineCategory);
        if (update) {
            return new ResponseResult(200, "修改成功", null);
        }
        return new ResponseResult(400, "修改失败", null);
    }
    @DeleteMapping("/deleteVaccineCategory")
    public ResponseResult deleteVaccineCategory(@RequestParam("id") Long id) {
        boolean delete = vaccineCategoryService.removeById(id);
        if (delete) {
            return new ResponseResult(200, "删除成功", null);
        }
        return new ResponseResult(400, "删除失败", null);
    }



}
